﻿using AutoMapper;
using MediatR;
using T_vehicle.API.Application.Command.ExpensesCommand;
using T_vehicle.Domain;
using T_vehicle.Infrastructure.Interfacec;

namespace T_vehicle.API.Application.CommandHandlers.ExpensesCommandHandlers
{
    public class AddExpensesCommandHandlers:IRequestHandler<AddExpensesCommand,int>
    {
        private readonly IExpensesRepository expensesRepository;
        private readonly IMapper mapper;

        public AddExpensesCommandHandlers(IExpensesRepository expensesRepository, IMapper mapper)
        {
            this.expensesRepository = expensesRepository;
            this.mapper = mapper;
        }

        public async Task<int> Handle(AddExpensesCommand request, CancellationToken cancellationToken)
        {

            var Info = mapper.Map<Expenses>(request);
            Info.CreateDate = DateTime.Now;
            return await expensesRepository.AddAsync(Info);


            //var Info = new Expenses();
            //Info.ExpensesTitle = request.ExpensesTitle;
            //Info.ExpensesType = request.ExpensesType;
            //Info.LicenNumber = request.LicenNumber;
            //Info.Money = request.Money;
            //Info.Head  = request.Head;
            //Info.Description = request.Description;
            //Info.Dateofuse = request.Dateofuse;
            //Info.Remark = request.Remark;
            //Info.CreateDate = DateTime.Now;
            //return await expensesRepository.AddAsync(Info);
        }
    }
}
